#include <unistd.h>
#include <sys/types.h>
#include "yys_thread.h"
#include "zlog.h"

extern void yys_thread_main();
extern void yys_thread_network();
extern void yys_thread_camera();

int process_thread(int threadNum)
{
    dzlog_debug("process thread threadNum=%d", threadNum);
    switch (threadNum)
    {
    case THREAD_NETWORK:{
        yys_thread_network();
    }
    break;

    case THREAD_CAMERA:{
        yys_thread_camera();
    }
    break;
    
    default:
        yys_thread_main();
        break;
    }

    return 0;
}

int create_thread()
{
    int threadNum = 0;
    for (threadNum = 0; threadNum < MAX_THREAD_NUM; ++threadNum) {
        pid_t pid = fork();
        if (pid > 0){
            dzlog_debug("parent thread, continue fork.");
            continue;
        }else if(pid == 0){
            dzlog_debug("sub thread, stop fork.");
            break;
        }else{
            dzlog_error("create new thread error.");
            return -1;
        }
    }
    dzlog_debug("exec thread, pid=%d, ppid=%d", getpid(), getppid());

    process_thread(threadNum);

    return 0;
}
